package com.besmart.workflow.core.service.helper;

import com.besmart.workflow.core.exception.OperationIndexCreationException;
import com.besmart.workflow.core.model.OperationIndex;

public class OperationIndexHelper {
	private static final int TWO_ELEMENTS = 2;
	private static final int SECOND_ELEMENT = 1;
	private static final int FIRST_ELEMENT = 0;

	public OperationIndex createInstance(String operationInfo) throws OperationIndexCreationException {
		String[] parts = operationInfo.split(":");
		if (parts.length == TWO_ELEMENTS) {
			String workflowId = parts[FIRST_ELEMENT];
			String operationId = parts[SECOND_ELEMENT];
			return new OperationIndex(workflowId, operationId);
		}
		else
		{
			throw new OperationIndexCreationException("Invalid operation info["+operationInfo+"] to parse");
		}
	}
}
